local t = Def.ActorFrame {};
local players = GAMESTATE:GetNumSidesJoined();
local delay = .1;
local scoretype = ThemePrefs.Get("ScoreType");

for player in ivalues(GAMESTATE:GetHumanPlayers()) do
	--Vars
	local Score = string.format("% 7d",STATSMAN:GetCurStageStats():GetPlayerStageStats(player):GetScore());
	local Combo = STATSMAN:GetCurStageStats():GetPlayerStageStats(player):GetCurrentCombo();
	local Marvelous = string.format("% 5d",STATSMAN:GetCurStageStats():GetPlayerStageStats(player):GetTapNoteScores("TapNoteScore_W1"));
	local Perfect = string.format("% 5d",STATSMAN:GetCurStageStats():GetPlayerStageStats(player):GetTapNoteScores("TapNoteScore_W2"));
	local Great = string.format("% 5d",STATSMAN:GetCurStageStats():GetPlayerStageStats(player):GetTapNoteScores("TapNoteScore_W3"));
	local Good = string.format("% 5d",STATSMAN:GetCurStageStats():GetPlayerStageStats(player):GetTapNoteScores("TapNoteScore_W4"));
	local Ok = string.format("% 5d",STATSMAN:GetCurStageStats():GetPlayerStageStats(player):GetHoldNoteScores("HoldNoteScore_Held"));
	local Miss = string.format("% 5d",STATSMAN:GetCurStageStats():GetPlayerStageStats(player):GetTapNoteScores("TapNoteScore_Miss"));
	local Almost = string.format("% 5d",STATSMAN:GetCurStageStats():GetPlayerStageStats(player):GetTapNoteScores("TapNoteScore_W5"));
	local NG = string.format("% 5d",STATSMAN:GetCurStageStats():GetPlayerStageStats(player):GetHoldNoteScores("HoldNoteScore_LetGo"));
	local PScore = FormatPercentScore(STATSMAN:GetCurStageStats():GetPlayerStageStats(player):GetPercentDancePoints())

	local EXScore = (Marvelous * 3) + (Perfect * 2) + Great + (Ok * 3);

	t[#t+1] = Def.ActorFrame{
		--Stats BG
		InitCommand=function(self)
			self:y(SCREEN_CENTER_Y-60);
			if players > 1 then
				self:x(player == PLAYER_1 and SCREEN_CENTER_X-180 or SCREEN_CENTER_X+180);
			else
				self:x(SCREEN_CENTER_X);
			end
		end;
		--Player label
		LoadFont("Common normal")..{
			InitCommand=function(self)
				self:settext(player == PLAYER_1 and "PLAYER 1" or "PLAYER 2");
				self:x(-140);
				self:y(-79);
			end;
		};
		--Difficulty
		LoadFont("Common normal")..{
			InitCommand=function(self)
				self:horizalign(right);
				local song = GAMESTATE:GetCurrentSong();
				local steps = GAMESTATE:GetCurrentSteps(player);
				local level = "";
				local diffLabel = CustomDifficultyToLocalizedString(GAMESTATE:GetCurrentSteps(player):GetDifficulty());

				if song and steps ~= nil then
					level = steps:GetMeter();
				end
				self:settext(diffLabel.." - "..level);
				self:x(160);
				self:y(-79);
			end;
		};
		--Stats
		--Marv
		Def.Quad{
			OnCommand=cmd(y,-40;zoomto,340,45;diffuseleftedge,color("#FFFFFF");diffuserightedge,color("#FFFFFF00");cropright,1;sleep,.466+(delay*0);linear,.367;cropright,0);
		};
		LoadFont("_song")..{
			InitCommand=cmd(x,-160;y,-40;horizalign,left;shadowlength,2;diffusealpha,0;sleep,.466+(delay*0);linear,.367;diffusealpha,1);
			OnCommand=function(self)
				self:settext("MARVELOUS");
			end;
		};
		LoadFont("_song")..{
			InitCommand=cmd(x,160;y,-40;horizalign,right;shadowlength,2;diffusealpha,0;sleep,.466+(delay*0);linear,.367;diffusealpha,1);
			OnCommand=function(self)
				self:settext(Marvelous);
			end;
		};
		--Perf
		Def.Quad{
			OnCommand=cmd(y,10;zoomto,340,45;diffuseleftedge,color("#FFFF00");diffuserightedge,color("#FFFF0000");cropright,1;sleep,.466+(delay*1);linear,.367;cropright,0);
		};
		LoadFont("_song")..{
			InitCommand=cmd(x,-160;y,10;horizalign,left;shadowlength,2;diffusealpha,0;sleep,.466+(delay*1);linear,.367;diffusealpha,1);
			OnCommand=function(self)
				self:settext("PERFECT");
			end;
		};
		LoadFont("_song")..{
			InitCommand=cmd(x,160;y,10;horizalign,right;shadowlength,2;diffusealpha,0;sleep,.466+(delay*1);linear,.367;diffusealpha,1);
			OnCommand=function(self)
				self:settext(Perfect);
			end;
		};
		--Great
		Def.Quad{
			OnCommand=cmd(y,60;zoomto,340,45;diffuseleftedge,color("#6363DC");diffuserightedge,color("#6363DC00");cropright,1;sleep,.466+(delay*2);linear,.367;cropright,0);
		};
		LoadFont("_song")..{
			InitCommand=cmd(x,-160;y,60;horizalign,left;shadowlength,2;diffusealpha,0;sleep,.466+(delay*2);linear,.367;diffusealpha,1);
			OnCommand=function(self)
				self:settext("GREAT");
			end;
		};
		LoadFont("_song")..{
			InitCommand=cmd(x,160;y,60;horizalign,right;shadowlength,2;diffusealpha,0;sleep,.466+(delay*2);linear,.367;diffusealpha,1);
			OnCommand=function(self)
				self:settext(Great);
			end;
		};
		--Good
		Def.Quad{
			OnCommand=cmd(y,110;zoomto,340,45;diffuseleftedge,color("#00FF00");diffuserightedge,color("#00FF0000");cropright,1;sleep,.466+(delay*3);linear,.367;cropright,0);
		};
		LoadFont("_song")..{
			InitCommand=cmd(x,-160;y,110;horizalign,left;shadowlength,2;diffusealpha,0;sleep,.466+(delay*3);linear,.367;diffusealpha,1);
			OnCommand=function(self)
				self:settext("GOOD");
			end;
		};
		LoadFont("_song")..{
			InitCommand=cmd(x,160;y,110;horizalign,right;shadowlength,2;diffusealpha,0;sleep,.466+(delay*3);linear,.367;diffusealpha,1);
			OnCommand=function(self)
				self:settext(Good);
			end;
		};
		--Miss+Boo
		Def.Quad{
			OnCommand=cmd(y,160;zoomto,340,45;diffuseleftedge,color("#00AEFC");diffuserightedge,color("#00AEFC00");cropright,1;sleep,.466+(delay*4);linear,.367;cropright,0);
		};
		LoadFont("_song")..{
			InitCommand=cmd(x,-160;y,160;horizalign,left;shadowlength,2;diffusealpha,0;sleep,.466+(delay*4);linear,.367;diffusealpha,1);
			OnCommand=function(self)
				self:settext("MISS");
			end;
		};
		LoadFont("_song")..{
			InitCommand=cmd(x,160;y,160;horizalign,right;shadowlength,2;diffusealpha,0;sleep,.466+(delay*4);linear,.367;diffusealpha,1);
			OnCommand=function(self)
				self:settext(Miss);
			end;
		};
		--Max Combo
		Def.Quad{
			OnCommand=cmd(y,210;zoomto,340,45;diffuseleftedge,color("#F63401");diffuserightedge,color("#F6340100");cropright,1;sleep,.466+(delay*5);linear,.367;cropright,0);
		};
		LoadFont("_song")..{
			InitCommand=cmd(x,-160;y,210;horizalign,left;shadowlength,2;diffusealpha,0;sleep,.466+(delay*5);linear,.367;diffusealpha,1);
			OnCommand=function(self)
				self:settext("MAX COMBO");
			end;
		};
		LoadFont("_song")..{
			InitCommand=cmd(x,160;y,210;horizalign,right;shadowlength,2;diffusealpha,0;sleep,.466+(delay*5);linear,.367;diffusealpha,1);
			OnCommand=function(self)
				self:settext(Combo);
			end;
		};
		--Points
		Def.Quad{
			OnCommand=cmd(y,260;zoomto,340,45;diffuse,color("#2F1B4F");diffusealpha,0;linear,.466;diffusealpha,1);
		};
		LoadFont("_song")..{
			InitCommand=cmd(y,260;zoom,.7;diffusealpha,0;linear,.466;diffusealpha,1);
			OnCommand=function(self)
				self:settext("Score: "..Score);
			end;
			Condition=scoretype == "Score";
		};
		LoadFont("_song")..{
			InitCommand=cmd(y,260;zoom,.7;diffusealpha,0;linear,.466;diffusealpha,1);
			OnCommand=function(self)
				self:settext("You've scored "..PScore.."!");
			end;
			Condition=scoretype == "Percent";
		};
		LoadFont("_song")..{
			InitCommand=cmd(y,260;zoom,.7;diffusealpha,0;linear,.466;diffusealpha,1);
			OnCommand=function(self)
				self:settext("You've scored "..EXScore.." points!");
			end;
			Condition=scoretype == "EXScore";
		};
	};

end

return t;